﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Mjudoku
{
    public partial class SettingsForm : Form
    {
        private View view;

        public SettingsForm(View view)
        {
            InitializeComponent();
            this.view = view;

            textBoxBlockMargin.Text = Settings.getInstance().BlockMarginValue.ToString();
            textBoxFontSize.Text = Settings.getInstance().MjudokuBoxFontSize.ToString();
            textBoxMargin.Text = Settings.getInstance().ObjectMarginValue.ToString();
            textBoxWindowsSize.Text = Settings.getInstance().WindowHeight.ToString();
            textBoxWindowsSize.Text = Settings.getInstance().WindowWidth.ToString();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                Settings.getInstance().BlockMarginValue = Convert.ToInt32(this.textBoxBlockMargin.Text);
                Settings.getInstance().MjudokuBoxFontSize = Convert.ToInt32(this.textBoxFontSize.Text);
                Settings.getInstance().ObjectMarginValue = Convert.ToInt32(this.textBoxMargin.Text);
                Settings.getInstance().WindowHeight = Convert.ToInt32(this.textBoxWindowsSize.Text);
                Settings.getInstance().WindowWidth = Convert.ToInt32(this.textBoxWindowsSize.Text);
            } catch (Exception ex) {
                MessageBox.Show("Something isn't correct. Textbox must contains only numbers.");
                return;
            }
            view.redraw();
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            TextBox box = (TextBox)sender;
            if (System.Text.RegularExpressions.Regex.IsMatch(box.Text, "[^0-9]"))
            {
                MessageBox.Show("Please enter only numbers.");
                box.Text = box.Text.Remove(box.Text.Length - 1);
                return;
            }
        }
    }
}
